/**
 * Created with Vim7.3 ubuntu12.04
 * @fileOverview : 
 * @author : Lyle <lylechen2014@gmial.com>
 * @since : 2014-09-30 11:02:27
 * @filename : static/logic/nmm/src/views/myProfileWorth.js
 * @version : 
 * @description : 
 */

define(function(require, exports, module){

    var myProfileWorthView,userObj, 
        mId = 'myProfileWorth',reRender = false,menuName = 'myProfileWorth',
        imglazyload = require('{component}imglazyload/zepto.imglazyload'),
        panel = require('{component}panel/zepto.panel'),
        tplN = require('{view}userNav.tpl'),
        tplS = require('{view}select.tpl'),
        tpl = require('{view}myProfileWorth.tpl');

    myProfileWorthView = Backbone.View.extend({

        template: _.template(tpl),
        templateS: _.template(tplS),
        templateN: _.template(tplN),

        bindEvt : function() {
            var tthis = this,dom = $('#'+mId);
            dom.find('.back').on('tap',function(e){
                window.location.href = '#myProfile/whole/custom2'; 
            });

            dom.find('.save').on('tap',function(e){
                var usr_id = userObj.account.usr_id;
                var obj = {
                    type: dom.find('#income').val(),
                    net_worth: dom.find('#netWorth').val()
                };

                var callback = function(){
                    userObj.detail.worth.income = obj.type;
                    userObj.detail.worth.net_worth = obj.net_worth;
                    share.cacheUserInfo(usr_id,userObj);
                    window.location.href = '#myProfile/whole/custom2'; 
                }
                share.updateProfile(usr_id,callback,obj);
            });
        },      

        render: function (obj) {
            if (!share.checkPermission(true)){return;};  
            userObj = share.getObjStorage(share.userInfo().usr_id);
            if ($('#'+mId).length < 1) { 
                $('body').append(this.template(lang));
           
                this.bindEvt(); 
            } else {
                $('#'+mId).css('display','block');
            }

             share.panel(panel,this.templateN,mId,menuName);
            this.incomeRender();
            this.netWorthRender();
        },
        
        incomeRender : function() {
            var select = share.getLocalStorage('ms_type');
            $('#'+mId).find('#income').html(this.templateS({obj : select, value : userObj.detail.worth.income}));
        },

        netWorthRender : function() {
            var select = share.getLocalStorage('ms_net_worth');
            $('#'+mId).find('#netWorth').html(this.templateS({obj : select, value : userObj.detail.worth.net_worth}));
        }

	});
	module.exports = myProfileWorthView;
})

